package com.zhaoxi.project.md.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONArray;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.md.domain.MdGoodsAttrValue;
import com.zhaoxi.project.md.service.impl.MdGoodsAttrValueServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 商品下面的属性值Controller
 *
 * @author zhaoxi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/md/mdValue")
public class MdGoodsAttrValueController extends BaseController
{
    @Autowired
    private MdGoodsAttrValueServiceImpl mdGoodsAttrValueService;

    /**
     * 查询商品下面的属性值列表
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(MdGoodsAttrValue mdGoodsAttrValue)
    {
        startPage();
        List<MdGoodsAttrValue> list = mdGoodsAttrValueService.selectMdGoodsAttrValueList(mdGoodsAttrValue);
        return getDataTable(list);
    }

    /**
     * 导出商品下面的属性值列表
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:export')")
    @Log(title = "商品下面的属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdGoodsAttrValue mdGoodsAttrValue)
    {
        List<MdGoodsAttrValue> list = mdGoodsAttrValueService.selectMdGoodsAttrValueList(mdGoodsAttrValue);
        ExcelUtil<MdGoodsAttrValue> util = new ExcelUtil<MdGoodsAttrValue>(MdGoodsAttrValue.class);
        util.exportExcel(response, list, "商品下面的属性值数据");
    }

    /**
     * 获取商品下面的属性值详细信息
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mdGoodsAttrValueService.selectMdGoodsAttrValueById(id));
    }

    /**
     * 获取id查询属性的值列表
     * @param request
     * @return
     */
    @GetMapping(value = "/getValueListById")
    public JSONArray getValueListById(@RequestParam("id") Long id,
                                      HttpServletRequest request)throws Exception {
        JSONArray dataArray = new JSONArray();
        try {
            dataArray = mdGoodsAttrValueService.getValueArrById(id);
        } catch(Exception e){
            e.printStackTrace();
        }
        return dataArray;
    }

    /**
     * 新增商品下面的属性值
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:add')")
    @Log(title = "商品下面的属性值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdGoodsAttrValue mdGoodsAttrValue)
    {
        return toAjax(mdGoodsAttrValueService.insertMdGoodsAttrValue(mdGoodsAttrValue));
    }

    /**
     * 修改商品下面的属性值
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:edit')")
    @Log(title = "商品下面的属性值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdGoodsAttrValue mdGoodsAttrValue)
    {
        return toAjax(mdGoodsAttrValueService.updateMdGoodsAttrValue(mdGoodsAttrValue));
    }

    /**
     * 删除商品下面的属性值
     */
    @PreAuthorize("@ss.hasPermi('md:mdValue:remove')")
    @Log(title = "商品下面的属性值", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mdGoodsAttrValueService.deleteMdGoodsAttrValueByIds(ids));
    }
}
